package com.chee.plant.server;

import org.apache.mina.common.IoSession;

public class SessionEntity {
	private int _userId;
	private IoSession _session;
	private long _lastUpdateState;
	private long _dueTime = 600000;
	public SessionEntity(int userId, IoSession session){
		this._userId = userId;
		this._session = session;
		this._lastUpdateState = System.currentTimeMillis();
	}
	public int getUserId(){
		return this._userId;
	}
	public void sendMessage(Message message){
		this._session.write(message.getContent());
	}
	public void refreshState(){
		this._lastUpdateState = System.currentTimeMillis();
	}
	public boolean isOverdue(){
		return (System.currentTimeMillis() - this._lastUpdateState) > this._dueTime;
	}
	public void close(){
		this._session.close();
	}
	public boolean isSession(IoSession sess){
		return this._session.equals(sess);
	}
}
